// pages/recommendationPage/main.js
const db = wx.cloud.database();
const commodit = db.collection('recommend');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    shows:false,
    sho:true, 
    tabCur: 0, //默认选中
    tabs: [{
        name: '精选',
        id: 0
      },
      {
        name: '手机',
        id: 1
      },
      {
        name: '美妆',
        id: 2
      },
      {
        name: '男装',
        id: 3
      },
      {
        name: '超市',
        id: 4
      },
      {
        name: '女装',
        id: 5
      },
      {
        name: '电脑',
        id: 6
      },
      {
        name: '数码',
        id: 8
      },
      {
        name: '母婴',
        id: 9
      },
      {
        name: '鞋包',
        id:10
      },
      {
        name: '家具',
        id:11
      },
      {
        name: '家电',
        id:12
      }
    ],
    shuzu:[]

  },
  async onShow(options) { //监听小程序启动或切前台
    /* this.huoqu() */
    this.huoqu("精选")

  },

  async huoqu(b){
    /* console.log(a)
    let b = this.data.tabs[a].name; */
    console.log(b)

    let res =await commodit.where({
      type:b
    }).get()
    console.log(res.data) 
    console.log(res.data[0]) 
    this.setData({
      shuzu:res.data 
    })
    
  },
  share:function(){
    let that = this;
    let sh = that.data.shows;
    let a = that.data.sho; 
    that.setData({
      shows: !sh, 
      sho : !a, 
    })
  },
  tabCur: function(e){ 
    this.setData({ 
      tabCur: e.tabCur.dataset.idx ,
    }) 
  }, 
   //选择条目
   tabSelect(e) {
    this.setData({
      tabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id - 2) * 100,
    })
    if(this.data.sho == false ){
      this.share()
    }
    let a = e.currentTarget.dataset.id;
    let b = this.data.tabs[a].name;
    console.log(b)
    this.huoqu(b)
  },
  //页面滚动触发
  onPageScroll(){
    if(this.data.sho == false ){
      this.share()
    }
  },
  dianji(e){
    shuzu = []
    console.log(e)
    if(e.currentTarget.dataset.type == "手机"){
      this.setData({
      shuzu: e.currentTarget.dataset.id,
     })
    }
   
  },
})